home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / weblibev / htmlpabc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-02  |  6.3 KB  |  171 lines

  1.  
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // Copyright 1995 by Potomac Software, Inc. Use of this material is subject to
  4. // the terms and conditions of the software license agreement.
  5.  
  6. #ifndef __HTMLPABC_H__
  7. #define __HTMLPABC_H__
  8.  
  9. #ifndef WEBLIB_NO_OWL
  10. #include <owl/window.h>
  11. #include <classlib/stacks.h>
  12. #endif
  13. #include "htmlpars.h"
  14. #include "dispatbc.h"
  15.  
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // HTML parser classes.
  18. //
  19. // The TWeblibHtmlAPI class is a simple C++ wrapper around the API.
  20.  
  21. class TWeblibHtmlAPI
  22. {
  23.   public:
  24.     TWeblibHtmlAPI();
  25.     TWeblibHtmlAPI(LPCSTR lpszFilename,WORD wOptions);
  26.     TWeblibHtmlAPI(LPCSTR lpszBuf,DWORD cbBuf,WORD wOptions);
  27.     virtual ~TWeblibHtmlAPI();
  28.  
  29.     BOOL IsGood() const;
  30.  
  31.     BOOL ParseFile(LPCSTR lpszFilename,WORD wOptions);
  32.     BOOL ParseBuf(LPCSTR lpszBuf,DWORD cbBuf,WORD wOptions);
  33.     BOOL EndParse();
  34.  
  35.     virtual BOOL EnumParseTree(HWND hwndNotify,UINT nMsg) const;
  36.  
  37.     HELEMENT GetChild(HELEMENT hElement) const;
  38.     HELEMENT GetParent(HELEMENT hElement) const;
  39.     HELEMENT GetSibling(HELEMENT hElement,WORD wRel) const;
  40.  
  41.     UINT GetElementType(HELEMENT hElement) const;
  42.     LPCSTR GetElementText(HELEMENT hElement) const;
  43.  
  44.     DWORD GetTextAttr(HELEMENT hElement) const;
  45.  
  46.     LPCSTR GetTagName(HELEMENT hElement) const;
  47.     UINT GetTagType(HELEMENT hElement) const;
  48.  
  49.     HTAGATTR GetTagAttr(HELEMENT hElement,HTAGATTR hTagAttr,WORD *pwType,LPSTR lpszAttr,
  50.         UINT cbAttr,LPSTR lpszValue,UINT cbValue) const;
  51.     LPCSTR ExtractTagAttr(HELEMENT hElement,LPSTR lpszAttr) const;
  52.  
  53.     HELEMENT FindText(HELEMENT hElement,LPCSTR lpszText) const;
  54.     HELEMENT FindSpecial(HELEMENT hElement,LPCSTR lpszSpecial) const;
  55.     HELEMENT FindComment(HELEMENT hElement,LPCSTR lpszCommentText) const;
  56.  
  57.     HELEMENT FindTagType(HELEMENT hElement,UINT nType) const;
  58.     HELEMENT FindTagName(HELEMENT hElement,LPCSTR lpszTag) const;
  59.     HELEMENT FindTagAttr(HELEMENT hElement,UINT nType,LPCSTR lpszAttr,
  60.         LPCSTR lpszValue) const;
  61.  
  62.     virtual BOOL EnumFindText(HELEMENT hElement,LPCSTR lpszText,
  63.         HWND hwndNotify,UINT nMsg) const;
  64.     virtual BOOL EnumFindSpecial(HELEMENT hElement,LPCSTR lpszSpecial,
  65.         HWND hwndNotify,UINT nMsg) const;
  66.     virtual BOOL EnumFindComment(HELEMENT hElement,LPCSTR lpszCommentText,
  67.         HWND hwndNotify,UINT nMsg) const;
  68.  
  69.     virtual BOOL EnumFindTagType(HELEMENT hElement,UINT nType,
  70.         HWND hwndNotify,UINT nMsg) const;
  71.     virtual BOOL EnumFindTagName(HELEMENT hElement,LPCSTR lpszTag,
  72.         HWND hwndNotify,UINT nMsg) const;
  73.     virtual BOOL EnumFindTagAttr(HELEMENT hElement,UINT nType,LPCSTR lpszAttr,
  74.         LPCSTR lpszValueText,HWND hwndNotify,UINT nMsg) const;
  75.  
  76.   protected:
  77.     HPARSE GetParseHandle() const
  78.         { return m_hParse; }
  79.  
  80.   private:
  81.     HPARSE m_hParse;
  82. };
  83.  
  84. ///////////////////////////////////////////////////////////////////////////////
  85. // If just want to use the above TWeblibHtmlAPI base class w/o OWL, then define
  86. // WEBLIB_NO_OWL in your project (for non-Borland C++ compilers and class libraries).
  87.  
  88. #ifndef WEBLIB_NO_OWL
  89.  
  90. ///////////////////////////////////////////////////////////////////////////////
  91. // The CWeblibHtml derived class handles enumeration notification automatically,
  92. // invoking the proper virtual event handler method when an event is received. To use,
  93. // derive your own class from TWeblibHtml and override the notification handlers.
  94.  
  95. class TWeblibHtml : public TWeblibHtmlAPI, public TWeblibDispatch
  96. {
  97.   public:
  98.     TWeblibHtml();
  99.     TWeblibHtml(LPCSTR lpszFilename,WORD wOptions);
  100.     TWeblibHtml(LPCSTR lpszBuf,DWORD cbBuf,WORD wOptions);
  101.     virtual ~TWeblibHtml();
  102.  
  103.     BOOL IsGood() const;
  104.  
  105.     ///////////////////////////////////////////////////////////////////////////
  106.     // New public methods intended to supplant all base class methods that take
  107.     // a notification window and message (notifications are sent to internal window).
  108.  
  109.     BOOL EnumParseTree(UINT nEnumID);
  110.  
  111.     BOOL EnumFindText(HELEMENT hElement,LPCSTR lpszText,UINT nEnumID);
  112.     BOOL EnumFindSpecial(HELEMENT hElement,LPCSTR lpszSpecial,UINT nEnumID);
  113.     BOOL EnumFindComment(HELEMENT hElement,LPCSTR lpszCommentText,UINT nEnumID);
  114.  
  115.     BOOL EnumFindTagType(HELEMENT hElement,UINT nType,UINT nEnumID);
  116.     BOOL EnumFindTagName(HELEMENT hElement,LPCSTR lpszTag,UINT nEnumID);
  117.     BOOL EnumFindTagAttr(HELEMENT hElement,UINT nType,LPCSTR lpszAttr,LPCSTR lpszValueText,
  118.         UINT nEnumID);
  119.  
  120.     ///////////////////////////////////////////////////////////////////////////
  121.     // Notification event handlers (override in your TWeblibHtml-derived class).
  122.  
  123.     virtual BOOL OnParseTree(WORD wType,HELEMENT hElement,UINT nEnumID);
  124.     virtual BOOL OnFindText(WORD wType,HELEMENT hElement,UINT nEnumID);
  125.     virtual BOOL OnFindSpecial(WORD wType,HELEMENT hElement,UINT nEnumID);
  126.     virtual BOOL OnFindComment(WORD wType,HELEMENT hElement,UINT nEnumID);
  127.     virtual BOOL OnFindTagType(WORD wType,HELEMENT hElement,UINT nEnumID);
  128.     virtual BOOL OnFindTagName(WORD wType,HELEMENT hElement,UINT nEnumID);
  129.     virtual BOOL OnFindTagAttr(WORD wType,HELEMENT hElement,UINT nEnumID);
  130.  
  131.     ///////////////////////////////////////////////////////////////////////////
  132.     // Internal window passes notification messages to Dispatch() method.
  133.  
  134.     virtual LRESULT Dispatch(UINT nMsg,WPARAM wParam,LPARAM lParam);
  135.  
  136.   private:
  137.     enum { MAX_ENUMSTACK = 16 };
  138.  
  139.     ///////////////////////////////////////////////////////////////////////////
  140.     // Override public base class methods that take a notification window as
  141.     // private (i.e., unavailable) since notifications are now sent to m_pWnd.
  142.  
  143.     virtual BOOL EnumParseTree(HWND hwndNotify,UINT nMsg) const;
  144.  
  145.     virtual BOOL EnumFindText(HELEMENT hElement,LPCSTR lpszText,
  146.         HWND hwndNotify,UINT nMsg) const;
  147.     virtual BOOL EnumFindSpecial(HELEMENT hElement,LPCSTR lpszSpecial,
  148.         HWND hwndNotify,UINT nMsg) const;
  149.     virtual BOOL EnumFindComment(HELEMENT hElement,LPCSTR lpszCommentText,
  150.         HWND hwndNotify,UINT nMsg) const;
  151.  
  152.     virtual BOOL EnumFindTagType(HELEMENT hElement,UINT nType,
  153.         HWND hwndNotify,UINT nMsg) const;
  154.     virtual BOOL EnumFindTagName(HELEMENT hElement,LPCSTR lpszTag,
  155.         HWND hwndNotify,UINT nMsg) const;
  156.     virtual BOOL EnumFindTagAttr(HELEMENT hElement,UINT nType,LPCSTR lpszAttr,
  157.         LPCSTR lpszValueText,HWND hwndNotify,UINT nMsg) const;
  158.  
  159.     BOOL PushEnumStack(UINT nEnumID);
  160.     BOOL PopEnumStack();
  161.  
  162.     TWindow *m_pWindow;
  163.     TStack<UINT> m_EnumStack;
  164. };
  165.  
  166. #endif    // WEBLIB_NO_OWL
  167.  
  168. #include "htmlpabc.inl"
  169.  
  170. #endif
  171.